package org.jeecg.modules.zcgl.vo;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.zcgl.entity.Region;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 区域表 存储树结构数据的实体类
 * <p>
 */
@Data
@Slf4j
public class RegionTreeModel extends Region implements Serializable{
	
    private static final long serialVersionUID = 1L;
    
    /** 对应Region中的id字段,前端数据树中的key*/
    private String key;

    /** 对应Region中的id字段,前端数据树中的value*/
    private String value;

    /** 对应depart_name字段,前端数据树中的title*/
    private String title;


    private Boolean isLeaf;

    private List<RegionTreeModel> children = new ArrayList<>();


    /**
     * 将Region对象转换成RegionTreeModel对象
     * @param region
     */
	public RegionTreeModel(Region region) {
		this.key = region.getId();
        this.value = region.getId();
        this.title = region.getRegionName();
        this.setId(region.getId());
        this.setParentId(region.getParentId());
        this.setRegionName(region.getRegionName());
        this.setRegionOrder(region.getRegionOrder());
        this.setDescription(region.getDescription());
        this.setRegionCode(region.getRegionCode());
        this.setStatus(region.getStatus());
        this.setDelFlag(region.getDelFlag());
        this.setCreateBy(region.getCreateBy());
        this.setCreateTime(region.getCreateTime());
        this.setUpdateBy(region.getUpdateBy());
        this.setUpdateTime(region.getUpdateTime());
        this.setRemark(region.getRemark());
    }

    public void setChildren(List<RegionTreeModel> children) {
        if (children==null){
            this.isLeaf=true;
        }
        this.children = children;
    }


    public RegionTreeModel() { }

    /**
     * 重写equals方法
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
			return true;
		}
        if (o == null || getClass() != o.getClass()) {
			return false;
		}
        RegionTreeModel model = (RegionTreeModel) o;
        return Objects.equals(getId(), model.getId()) &&
                Objects.equals(getParentId(), model.getParentId()) &&
                Objects.equals(getRegionName(), model.getRegionName()) &&
                Objects.equals(getRegionOrder(), model.getRegionOrder()) &&
                Objects.equals(getDescription(), model.getDescription()) &&
                Objects.equals(getRegionCode(), model.getRegionCode()) &&
                Objects.equals(getStatus(), model.getStatus()) &&
                Objects.equals(getDelFlag(), model.getDelFlag()) &&
                Objects.equals(getCreateBy(), model.getCreateBy()) &&
                Objects.equals(getCreateTime(), model.getCreateTime()) &&
                Objects.equals(getUpdateBy(), model.getUpdateBy()) &&
                Objects.equals(getUpdateTime(), model.getUpdateTime()) &&
                Objects.equals(getRemark(), model.getRemark()) &&
                Objects.equals(children, model.children);
    }
    
    /**
     * 重写hashCode方法
     */
    @Override
    public int hashCode() {

        return Objects.hash(getId(), getParentId(), getRegionName(), getRegionOrder(), getDescription(), getRegionCode(),
        		getStatus(), getDelFlag(), getCreateBy(), getCreateTime(), getUpdateBy(), getUpdateTime(), getRemark(),
        		children);
    }

}
